package LCR_code;

import java.util.HashSet;


/**
 * @author blh
 * @date 2024年08月16日 13:08
 */
public class LCR_157_816 {
    HashSet<String> res = new HashSet<>();
    int len;

    public String[] goodsOrder(String goods) {
        len = goods.length();
        int[] seen = new int[len];
        char[] chars = goods.toCharArray();
        backTrace(new StringBuilder(), seen, chars);

        return res.toArray(new String[res.size()]);
    }

    private void backTrace(StringBuilder sb, int[] seen, char[] goods) {
        if (sb.length() == len) {
            res.add(sb.toString());
            return;
        }
        for (int i = 0; i < len; i++) {
            if (seen[i] == 1) {
                continue;
            } else {
                sb.append(goods[i]);
                seen[i] = 1;
                backTrace(sb, seen, goods);
                seen[i] = 0;
                sb.deleteCharAt(sb.length() - 1);
            }
        }
    }
}
